﻿<UserControl x:Class="IS_Ever_Green.View.EmployeeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:IS_Ever_Green.View" 
             xmlns:viewModel="clr-namespace:IS_Ever_Green.ViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="450" 
             d:DesignWidth="1100"
             >

<UserControl.DataContext>
    <viewModel:EmployeeViewModel/>
</UserControl.DataContext>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="120"/>
            </Grid.ColumnDefinitions>

            <Button Grid.Column="1"                          
                    Content="Добавить"                            
                    FontSize="12"
                    FontFamily="Montserrat"
                    Cursor="Hand"
                    BorderThickness="0"
                    Foreground="{StaticResource secondaryTextColor}"
                    VerticalAlignment="Top"
                    Click="AddEmployee_Click"
                    >

                <Button.Style>
                    <Style TargetType="Button">
                        <Setter Property="Background" Value="{StaticResource primaryButtonColor}"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border Height="30"
                                                    CornerRadius="15"
                                                    Background="{TemplateBinding Background}">
                                        <ContentPresenter VerticalAlignment="Center"
                                                                    HorizontalAlignment="Center"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="{StaticResource primaryButtonHoverColor}"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </Grid>

        <Border Grid.Row="1"
                Background="{StaticResource panelColorMain}"
                CornerRadius="10" 
                Padding="5">

            <DataGrid ItemsSource="{Binding EmployeesList}"
                      SelectedItem="{Binding SelectedEmployee, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      AutoGenerateColumns="False" 
                      ColumnWidth="*"
                      Background="{StaticResource panelColorMain}"
                      BorderThickness="0"
                      GridLinesVisibility="None"
                      FocusVisualStyle="{x:Null}"
                      CanUserAddRows="False"
                      >

                <DataGrid.Resources>
                    <Style TargetType="{x:Type DataGridCell}">
                        <Setter Property="FontSize" Value="25"/>
                        <Setter Property="VerticalAlignment" Value="Center"/>
                        <Setter Property="FontFamily" Value="Montserrat"/>
                    </Style>
                    <Style TargetType="{x:Type DataGridRowHeader}">
                        <Setter Property="Width" Value="0"/>
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <ContentControl Content="{Binding}"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGrid.Resources>
                
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="Background" Value="Transparent"/>
                        <Setter Property="Foreground" Value="{StaticResource panelTextColor}"/>
                        <Setter Property="Padding" Value="10,0,0,10"/>
                        <Setter Property="FontFamily" Value="Montserrat"/>
                        <Setter Property="FontSize" Value="15"/>
                    </Style>
                </DataGrid.ColumnHeaderStyle>
                
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding UserId}" Width="50" Header="ID" IsReadOnly="True"/>
                    <DataGridTextColumn Binding="{Binding LoginUser, UpdateSourceTrigger = PropertyChanged}" Width="150" Header="Login User"/>
                    <DataGridTextColumn Binding="{Binding FirstName, UpdateSourceTrigger = PropertyChanged}" Width="120" Header="First Name"/>
                    <DataGridTextColumn Binding="{Binding LastName, UpdateSourceTrigger = PropertyChanged}" Width="120" Header="Last Name"/>
                    <DataGridTextColumn Binding="{Binding Email, UpdateSourceTrigger = PropertyChanged}" Width="100" Header="Email"/>
                    <DataGridTextColumn Binding="{Binding NumberPhone, UpdateSourceTrigger = PropertyChanged}" Width="150" Header="Number Phone"/>
                    <DataGridTextColumn Binding="{Binding Password, UpdateSourceTrigger = PropertyChanged}" Width="100" Header="Password"/>
                    <DataGridTextColumn Binding="{Binding DeliveryAddress, UpdateSourceTrigger = PropertyChanged}" Width="150" Header="Delivery Address"/>

                    <DataGridTemplateColumn Width="110" Header="Действие">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Button Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                            Margin="5 5 15 5"
                                            Height="25"
                                            Width="25"
                                            Cursor="Hand"
                                            BorderThickness="0">    

                                        <Button.Style>
                                            <Style TargetType="Button">
                                                <Setter Property="Background" Value="Transparent"/>
                                                <Style.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter Property="Background" Value="Transparent"/>
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>

                                        <Button.Template>
                                            <ControlTemplate TargetType="Button">
                                                <Border CornerRadius="15"
                                            Background="{TemplateBinding Background}">

                                                    <ContentPresenter VerticalAlignment="Center"
                                                          HorizontalAlignment="Center"/>

                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>

                                        <Button.Background>
                                            <ImageBrush ImageSource="/Images/Edit.png"/>
                                        </Button.Background>
                                    </Button>

                                    <Button Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                Margin="5 5 15 5"
                                Height="25"
                                Width="25"
                                Cursor="Hand"
                                BorderThickness="0">

                                        <Button.Style>
                                            <Style TargetType="Button">
                                                <Setter Property="Background" Value="Transparent"/>
                                                <Style.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter Property="Background" Value="Transparent"/>
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>

                                        <Button.Template>
                                            <ControlTemplate TargetType="Button">
                                                <Border CornerRadius="15"
                                            Background="{TemplateBinding Background}">

                                                    <ContentPresenter VerticalAlignment="Center"
                                                          HorizontalAlignment="Center"/>

                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>

                                        <Button.Background>
                                            <ImageBrush ImageSource="/Images/Delete.png"/>
                                        </Button.Background>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                </DataGrid.Columns>
            </DataGrid>
        </Border>
    </Grid>

</UserControl>
